﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core
{
    public class Delegates
    {
        internal delegate void FeedBack(int param);

        public void TestDelegate()
        {
            int i = 12;

            FeedBack fb = new FeedBack(ShowMsg);
            fb += new FeedBack(Add);
            // 直接调用
            fb(i);
            // invoke 调用
            fb.Invoke(i);

            Console.WriteLine("GetInvocationList:" + fb.GetInvocationList().Length);

            Console.WriteLine("Type:" + fb.Target.GetType());

            // 委托链Length>1时，通过Method方法访问只返回最后一个Method的方法名
            Console.WriteLine("Method:" + fb.Method.Name.ToString());
        }

        /// <summary>
        /// show msg
        /// </summary>
        public void ShowMsg(int param)
        {
            Console.WriteLine(param);
        }

        /// <summary>
        /// Add
        /// </summary> 
        public void Add(int param)
        {
            param++;
            Console.WriteLine(param);
        }


    }
}
